<template>
	<page-body>
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center examinationIncrow_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub examinationIncrow_fd0_0'>
					<view class='flex flex-wrap align-center examinationIncrow_fd0_0_c0' @tap.stop="nav">
						<text class='fu-iconfont2  examinationIncrow_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center'>
						<text class='examinationIncrow_fd0_0_c1_c0'>详情</text>
					</view>
					<view class='flex flex-wrap align-center justify-end examinationIncrow_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<template>
				<view class="flex benben-flex-layout flex-wrap align-center">
					<!--initial-time  指定视频初始播放位置，单位为秒（s）。 @ended当播放到末尾时触发 ended 事件 -->
					<!--   <video class='flex  examinationIncrow_fd1_0' :src="list.video.path" controls='true' x5-video-player-type="h5"
            enable-progress-gesture='fasle' :show-fullscreen-btn='true' object-fit="fill" :poster="list.video.thumb"
            @timeupdate="getTimeFunc($event)" draggable="false" @ended="videoEnd" :initial-time="list.time*1" @pause="videoEnd"  @seeking="handleSeeking" @seeked="handleSeeked"
   ></video> -->
					<video v-if="xcxzt==0" id="myVideo" class='flex  examinationIncrow_fd1_0' :src="list.video.path"
						x5-video-player-type="h5" :enable-progress-gesture='fasle' :show-center-play-btn="true"
						:show-fullscreen-btn='true' object-fit="fill" :poster="list.video.thumb"
						@timeupdate="getTimeFunc($event)" draggable="false" @ended="videoEnd"
						:initial-time="list.time*1" @pause="videoEnd" @seeking="handleSeeking"
						@seeked="handleSeeked"></video>

					<view class="" style="margin-top: 30rpx;width: 100%;">
						<view class="enclosures" v-if="list.enclosure && xcxzt==0">
							<view class="titles">课节附件</view>
							<view class="enclosure" v-for="(item,ind) in list.enclosure" :key="ind">
								<view>{{item.name}}</view>
								<!-- child.file,aid -->
								<button class='datum_fd2' v-if="item.mime=='video/mp4'"
									@tap.stop="list.video.path=item.path">观看</button>
								<button class='datum_fd2' v-else @tap.stop="handlePreview(item.path,item.name)">查看</button>
							</view>
						</view>

						<view class='flex flex-direction flex-wrap align-stretch examinationIncrow_fd1_1'>
							<text class='examinationIncrow_fd1_1_c0 titles'>内容简介</text>
							<view class="" v-if="list.content">
								<jyf-parser class='examinationIncrow_fd1_1_c1' :html="list.content | richTextFormat">
								</jyf-parser>
							</view>
							<view class="" v-else>
								暂无内容
							</view>
						</view>
					</view>
				</view>
			</template>

			<!---flex布局flex布局结束-->


		</view>
	</page-body>
</template>

<script>
	import filePreview from '@/common/utils/filePreview.js'

	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		mixins: [filePreview],
		components: {},


		data() {
			return {
				"list": {
					video: {
						path: '',
						thumb: ''
					},
					"aid": "",
					"file": [],
					"content": "",
					"create_time": "",
					"time": ""
				},
				"time": "",
				"aid": "",
				isfinish: 0, //0 未看 1观看中  2已经观看完成
				currentTime: 0,
				allowSeek: false, // 控制是否允许跳转
				group: 1, //1学生 2教师
				xcxzt:1,
				period:0,//观看进度
				isjz:false,//是否更新记录
			};
		},
		computed: {

		},
		watch: {},
		onLoad(options) {
			let {
				aid,
				isfinish,
				period
			} = options
			if (aid !== undefined) this.aid = aid
			if (isfinish !== undefined) this.isfinish = isfinish
			if (period !== undefined) this.period = period
			this.getDataFunc()
		},
		onUnload() {
			this.videoEnd()
		},
		onReady() {

		},
		onShow() {
			this.isjz=false
			this.group = uni.getStorageSync('USER_GROUP')
			this.getzt()
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			async getzt(){
				let info = await this.$api.get(global.apiUrls.post64534cbb2c352, {
					code: 'app_grounding_status'
				});
				console.log(info.data.data)
				// console.log(this)
				this.xcxzt=info.data.data
				// #ifndef MP-WEIXIN
				this.xcxzt=0
				//  #endif
				// this.xcxzt=0
			},
			nav() {
				// this.videoEnd()
				uni.navigateBack(1)
			},
			//获取数据
			async getDataFunc() {
				//请求方法
				//数据验证

				let datalist = await this.$api.get(global.apiUrls.post649a38efad9e0, {
					aid: this.aid
				});

				if (datalist.data.code != 1) {
					this.$message.info(datalist.data.msg);
					return
				}
				let infolist = datalist.data;
				this.list = infolist.data
				// this.list.video.thumb='https://ttk-saas.oss-cn-beijing.aliyuncs.com/m4037/2025-06-21/019ac3b4648a0fba3a4a792dc586e5ce1750496986244.mp4?x-oss-process=video/snapshot,t_1,m_fast,ar_auto'

				console.log("aid=>", this.list)
			},
			//获取时间
			getTimeFunc(e) {
				// var currentTime = parseInt(e.detail.currentTime);
				// this.time = Math.floor(e.detail.currentTime);
				var isReady = 1; // 是否开启可以视频快进 1 禁止开启
				//跳转到指定播放位置 initial-time 时间为秒
				let that = this;
				//播放的总时长
				var duration = e.detail.duration;
				//实时播放进度 秒数
				var currentTime = parseInt(e.detail.currentTime);
				//当前视频进度
				console.log("视频播放到第" + currentTime + "秒") //查看正在播放时间，以秒为单位


				if (that.time == 0) {
					var jump_time = parseInt(that.video_real_time) + parseInt(that.time);
				} else {
					var jump_time = parseInt(that.time);
				}
				console.log(that.time)
				// if(that.time )
				if (isReady == 1) {
					if (currentTime > jump_time && currentTime - jump_time > 3) {
						let videoContext = uni.createVideoContext('myVideo');
						videoContext.seek(that.time);
						currentTime = this.time;
						uni.showToast({
							title: '该视频不能快进',
							icon: 'none',
							duration: 2000
						});
					}
				}
				that.time = currentTime; //实时播放进度
				console.log(that.time)
				// console.log(val)

				// console.log("获取到的数据=>", this.time)

			},
			videoEnd() {
				if (this.group == 1) {
					this.gettf49a368d75e14Func()
				}


			},

			handleSeeking(e) {
				console.log(this.allowSeek)
				if (!this.allowSeek) {
					// 不允许跳转时，立即跳回原来的时间点
					this.videoContext.seek(this.currentTime);
				}
			},
			handleSeeked(e) {
				this.currentTime = e.detail.currentTime;
			},

			// 打开学习资料
			seePdf(file, aid) {
				let _this = this;
				let id = aid;
				let url = file;
				// let files = uni.getStorageSync('files') ? JSON.parse(uni.getStorageSync('files')) : {}
				// console.log(files)
				// #ifdef APP-PLUS

				let files = uni.getStorageSync('files') ? JSON.parse(uni.getStorageSync('files')) : {}
				console.log(files)
				if (files[id]) {
					// 已下载的文件直接打开
					plus.runtime.openFile(files[id], {}, (res) => {
						console.log("res=>", res);
						// downloadFile()
					})
				} else {
					downloadFile()
				}

				function downloadFile() {
					uni.showLoading({
						title: '加载中'
					})
					const dtask = plus.downloader.createDownload(url, {}, function(d, status) {
						if (status == 200) {
							console.log('保存成功')
							uni.hideLoading();
							//下载成功,d.filename是文件在保存在本地的相对路径，使用下面的API可转为平台绝对路径
							//const fileSaveUrl = plus.io.convertLocalFileSystemURL(d.filename);
							files[id] = d.filename
							uni.setStorageSync('files', JSON.stringify(files))
							plus.runtime.openFile(d.filename) //选择软件打开文件
						} else {
							//下载失败
							plus.downloader.clear() //清除下载任务
							uni.hideLoading();
							uni.showToast({
								title: '文档加载失败，请稍后再试',
								icon: 'none',
							})
						}
					})
					dtask.start()
				}
				// #endif

				// #ifdef H5
				window.open(url)
				// #endif
				// this.fileUrl = file[0].path;
				// this.showPreview = true;
				// let _this = this;
				// _this.means_id = aid;
				// uni.showLoading({
				// 	title: '加载中...'
				// })

				// uni.downloadFile({
				// 	url: file[0].path,
				// 	success: function(res) {
				// 		var filePath = res.tempFilePath;
				// 		uni.hideLoading();
				// 		uni.openDocument({
				// 			filePath: filePath,
				// 			showMenu: true,
				// 			success: function(res) {
				// 				console.log('打开文档成功');
				// 			}
				// 		});
				// 	},
				// 	fail: function(err) {
				// 		uni.hideLoading();
				// 		uni.showToast({
				// 			title: '文档加载失败，请重试',
				// 			icon: 'none'
				// 		})
				// 	}
				// });
			},
			handlePreview(fileUrl,fileName) {
			      // const fileUrl = 'https://example.com/files/document.pdf'
			      // const fileName = '项目文档.pdf'
				  console.log(fileUrl)
				   console.log(fileName)
			      this.previewFile(fileUrl, fileName)
			},
			async addRecord() {
				let data64910ea324123 = await this.$api.post(global.apiUrls.post64910ea324123, {
					means_id: this.aid,
					demand: this.time
				})
				console.log("触发了=>", data64910ea324123)
				if (data64910ea324123.data.code != 1) {
					// this.$message.info(data64910ea324123.data.msg);
					return
				}
			},
			//添加观看时长
			async gettf49a368d75e14Func() {
				if(this.isjz){
					return
				}
				//请求方法
				//数据验证
				if(this.period == '100'){
					// this.addRecord()
					return
				}
				this.isjz=true
				let data649a368d75e14 = await this.$api.post(global.apiUrls.post649a368d75e14, {
					means_id: this.aid,
					time: this.time
				});

				if (data649a368d75e14.data.code != 1) {
					this.$message.info(data649a368d75e14.data.msg);
					return
				}
				let info649a368d75e14 = data649a368d75e14.data;
				this.addRecord()

			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: #Fff;
		background-size: 100% auto;
	}

	.enclosures {
		width: 100%;
		background-color: #f6f6f6;
		// padding: 35rpx 0;

		.titles {
			font-size: 32rpx;
			color: #333;
			line-height: 60rpx;
			// margin-bottom: 15rpx;
			font-weight: 600;
			margin-left: 35rpx;
		}

		.enclosure {
			display: flex;
			justify-content: space-between;
			align-items: center;
			background-color: #fff;
			padding: 30rpx 25rpx;
			width: 100%;
			// border-radius: 16rpx;
		}

		.enclosure:not(:first-child) {
			margin-top: 2rpx;
		}
	}

	.datum_fd2 {
		border: 1px solid rgba(204, 34, 28, 1);
		background: rgba(205, 150, 45, 0.1);
		border-radius: 33rpx 33rpx 33rpx 33rpx;
		width: 120rpx;
		line-height: 48rpx;
		font-size: 24rpx;
		color: rgba(204, 34, 28, 1);
		height: 48rpx;
	}

	.examinationIncrow_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.examinationIncrow_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 700;
		color: #333333;
		line-height: 50rpx;
	}

	.examinationIncrow_fd0_0_c0_c0 {
		font-size: 36rpx;
		color: #333;
	}

	.examinationIncrow_fd0_0_c0 {
		width: 120rpx;
	}

	.examinationIncrow_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	::v-deep .examinationIncrow_fd1_1_c1 {
		width: 100%;
	}

	.examinationIncrow_fd1_1_c0 {
		margin: 0rpx 0rpx 20rpx 0rpx;
		background-color: #f6f6f6;
		width: 750rpx;
		// margin-top: 35rpx;
		height: 60rpx;
		// padding-top: 10rpx;
		box-sizing: border-box;
		margin-left: -35rpx;
		padding-left: 35rpx;

		font-size: 32rpx;
		color: #333;
		line-height: 60rpx;
		// margin-bottom: 15rpx;
		font-weight: 600;
		// margin-left: 35rpx;
	}

	.examinationIncrow_fd1_1 {
		width: 100%;
		padding: 0 32rpx 24rpx 32rpx;
	}

	.examinationIncrow_fd1_0 {
		width: 750rpx;
		height: 500rpx;
		border-radius: 10rpx 10rpx 10rpx 10rpx;
	}
</style>
